Skip to content

fix(cli): use HasPrefix for haproxy flag matching to avoid advertise-http-addr collision - #173090

Open
waterWang wants to merge 2 commits into
cockroachdb:masterfrom
waterWang:fix/haproxy-advertise-http-addr-substring-match
Open

fix(cli): use HasPrefix for haproxy flag matching to avoid advertise-http-addr collision#173090
waterWang wants to merge 2 commits into
cockroachdb:masterfrom
waterWang:fix/haproxy-advertise-http-addr-substring-match

Conversation

@waterWang

Copy link
Copy Markdown

Description

Fixes #172968

Problem: nodeStatusesToNodeInfos() in pkg/cli/haproxy.go uses strings.Contains to match http-addr and http-port flags in node startup arguments. This substring match incorrectly matches --advertise-http-addr as --http-addr, because "http-addr" is a substring of "advertise-http-addr".

When a node is started with --advertise-http-addr before --http-addr:

  1. The sub-string match triggers on --advertise-http-addr
  2. fs.Parse() is called but the --advertise-http-addr flag isn't registered in the local flag set
  3. Parse returns an error (discarded with _ =)
  4. The loop breaks, and the real --http-addr is never reached
  5. The generated HAProxy config uses the default HTTP port (8080) instead of the configured port

Fix: Replace strings.Contains with strings.HasPrefix for exact flag name matching. This ensures --advertise-http-addr is not matched as --http-addr.

Testing: Added a test case that reproduces the exact scenario: --advertise-http-addr=node.example:9999 followed by --http-addr=node.example:5678. The test verifies the correct port (5678) is used in the generated config.

@blathers-crl

blathers-crl Bot commented Aug 4, 2026

Copy link
Copy Markdown

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

I was unable to automatically find a reviewer. You can try CCing one of the following members:

  • A person you worked with closely on this PR.
  • The person who created the ticket, or a CRDB organization member involved with the ticket (author, commenter, etc.).
  • Join our community slack channel and ask on #contributors.
  • Try find someone else from here.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl Bot added O-community Originated from the community X-blathers-untriaged blathers was unable to find an owner labels Aug 4, 2026
@cockroachlabs-cla-agent

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-community Originated from the community X-blathers-untriaged blathers was unable to find an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: gen haproxy can ignore --http-addr after --advertise-http-addr

1 participant